<template>
	<view class="index-list animated fadeIn fast">
		<view class="index-list1 u-f-ac u-f-jsb">
			<view class="u-f-ac" v-if="item.topicer.name" style="width: 100%; background-color: #FFFFFF;" >
				<image :src="item.topicer.avatar_url" mode="widthFix" lazy-load></image>
				<text style="color: #007AFF;"> {{item.topicer.name}} </text>
				<view v-if="isguanzhu" @tap="guanzhu" class="icon iconfont icon-guanzhu" style=" padding-left: 20upx; color: #007AFF; font-size: 70upx;"></view>
			
			</view>
			<view class="uni-media-list-text-bottom" style="background-color: #FFFFFF;">
				<text></text>
				<text>{{item.createdAt | FormatDate('yyyy-MM-dd HH:mm:ss') }}</text>
			</view>
		</view>
		<view class="uni-media-list" @tap="opendetail(item)">
			<view class="uni-media-list-body">
				<view class="uni-media-list-text-top" style="height: 90upx;">
					于<text  style="font-size: large; color: #007AFF; padding-left: 5px; padding-right: 5px;"> {{item.location}}</text>
					的<text  style="font-size: large; color: #007AFF; padding-left: 5px;"> {{item.clinic}}</text>,
				</view>
				<view class="uni-media-list-text-top" >
					向<text style="font-size: large; color: #007AFF; padding-left: 5px;padding-right: 5px;"> {{item.doctor}}</text>
					求诊<text style="font-size: large; color: #007AFF; padding-left: 5px;"> {{item.diseseName}}</text>
				</view>
			</view>
			<!-- <image class="uni-media-list-logo" :src="item.casePics[0]"></image> -->
		</view>
		<view class="index-list4 u-f-ac u-f-jsb">
			<view class="u-f-ac">
				<view class="u-f-ac" :class="{'active':false}" @tap="goDianzan(item,'dianzan')">
					<view class="icon iconfont icon-good-fill icon-style"></view>
					{{dianzan}}
				</view>
				<view class="u-f-ac" @tap="goDianzan(item,'shoucang')">
					<view class="icon iconfont icon-favorites icon-style"></view>
					{{shoucang}}

				</view>
			</view>
			<view class="u-f-ac">
				<view class="u-f-ac">
					<view class="icon iconfont icon-pinglun-copy "></view>
					{{item.commentNum}}
				</view>
				<view class="u-f-ac">
					<view class="icon iconfont icon-forward-null icon-style"></view>
					0
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import config from "@/common/config.js"
	export default {
		props: {
			item: Object,
			index: Number,
			from:String
		},
		data() {
			return {
				isguanzhu: false,
				infonum: 9,
				dianzan :this.item.dianZanNum,
				shoucang:this.item.shouCangNum
			}
		},

		methods: {
			guanzhu() {
				this.isguanzhu = true;
				uni.showToast({
					title: '关注成功',
				});
			},
			// 顶踩
			goDianzan(item, type) {
				var token = uni.getStorageSync(config.token);
				var ty = '';
				var msg='';
				if(type=='dianzan'){
					ty = 'favirate';
					msg='点赞';
				}
				if(type=='shoucang'){
					ty='collecte';
					msg='收藏';
				}
				var url = config.baseUrl + '/users/'+ty+'/' + item._id;
				uni.request({
					method: 'GET',
					url: url, //仅为示例，并非真实接口地址。
					header: {
						'content-type': 'application/json', //自定义请求头信息
						'Authorization': 'Bearer ' + token //通过登录接口，生成新的token
					},
					success: (res) => {
						console.log(res);
						var statusCode = res.statusCode;
						console.log(statusCode);
						if (200 == statusCode) {
							if(type=='dianzan'){
								this.dianzan = this.dianzan+1;
							}
							if(type=='shoucang'){
								this.shoucang = this.shoucang+1;
							}
							
							uni.showToast({
								title: msg+'成功',
								duration: 2000,
							});
						} else if (204 == statusCode) {
							
							uni.showToast({
								title: "已"+msg+"过了",
								duration: 2000,
							});
						} else if (401 == statusCode) {
							uni.navigateTo({
								url: '../loginnew/loginnew'
							})

						} else {
							uni.showToast({
								title: msg+"失败",
								duration: 2000,
							});
						}
					},
					fail: (res) => {
						uni.showToast({
							title: msg+"失败",
						});
					}
				});

			},
			// 进入详情页
			opendetail(item) {
				var rootTopicId = item._id;
				var url = '../recorderdetail/recorderdetail?id=' + rootTopicId;
				console.log(this.from+"xxxxxxxxxxxx");
				if(this.from=='我的记录'){
					url = '../recorderdetail/recorderdetail?id=' + rootTopicId + '&from=我的记录';
				}
				if(this.from=='我的收藏'){
					url = '../recorderdetail/recorderdetail?id=' + rootTopicId + '&from=我的收藏';
				}
				if(this.from=='搜索页'){
					url = '../recorderdetail/recorderdetail?id=' + rootTopicId + '&from=搜索页';
				}
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style scoped>
	/* .index-list {
		padding: 20upx;
		border-bottom: 1upx solid #EEEEEE;
		
	} */
	.index-list {
		padding: 20upx;
		border-bottom: 1upx solid #EEEEEE;
		background-color: #FFFFFF;
		box-shadow: #C8C7CC;
		
		margin-top: 30upx;
	
		border-radius: 20upx;
	}

	.index-list1>view:first-child {
		color: #999999;
	}

	.index-list1>view:first-child image {
		width: 85upx;
		height: 85upx;
		border-radius: 100%;
		margin-right: 10upx;
	}

	.index-list1>view:last-child {
		background: #F4F4F4;
		border-radius: 5upx;
		/* padding: 0 10upx; */
	}

	.index-list2 {
		padding-top: 15upx;
		font-size: 32upx;
	}

	.index-list3 {
		position: relative;
		padding-top: 15upx;
	}

	.index-list3>image {
		width: 100%;
		border-radius: 20upx;
	}

	.index-list4 view {
		color: #999999;
	}

	.index-list4 {
		padding: 15upx 0;
	}

	.index-list4>view>view>view,
	.index-list4>view>view:first-child {
		margin-right: 10upx;
	}

	.index-list-play {
		position: absolute;
		font-size: 140upx;
		color: #FFFFFF;
	}

	.index-list-playinfo {
		position: absolute;
		background: rgba(51, 51, 51, 0.72);
		color: #FFFFFF;
		bottom: 8upx;
		right: 8upx;
		border-radius: 40upx;
		font-size: 22upx;
		padding: 0 12upx;
	}

	.index-list4 .active,
	.index-list4 .active>view {
		color: #C5F61C;
	}

	.icon-style {
		font-size: 45upx;
	}
	.uni-media-list-logo {
		width: 180upx;
		height: 140upx;
	}
	
	.uni-media-list-body {
		height: auto;
		justify-content: space-around;
	}
	
	.uni-media-list-text-top {
		height: 74upx;
		font-size: 28upx;
		overflow: hidden;
	}
	
	.uni-media-list-text-bottom {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}
</style>
